/*
 * 拖拽指令
 */
export default {
    mounted(el, binding) {
        let excludeNode = ['INPUT','PATH','SVG','VIDEO'];
        el.onmousedown = (e) => {
            let obj = binding.value;
            // console.log(binding.value, e.target.className)
            if(excludeNode.some(t => e.target.nodeName.toUpperCase().indexOf(t) > -1)) return;
            // if(e.target.nodeName.toUpperCase() == "INPUT" || e.target.nodeName.toUpperCase() == "SVG") return;
            if(obj.className.some(t => e.target.className.indexOf(t) > -1)) return;
            //算出鼠标相对元素的位置
            let disX = e.clientX - el.offsetLeft;
            let disY = e.clientY - el.offsetTop;
            
            document.onmousemove = (e)=>{
                //用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
                let left = e.clientX - disX;    
                let top = e.clientY - disY;
              
                //绑定元素位置到positionX和positionY上面
                // this.positionX = top;
                // this.positionY = left;
        
                //移动当前元素
                el.style.left = left + 'px';
                el.style.top = top + 'px';
                if(obj.data){
                    obj.data.left = left;
                    obj.data.top = top;
                }
                // obj.left = left + 'px';
                // obj.top = top + 'px';
            };
            document.onmouseup = (e) => {
                document.onmousemove = null;
                document.onmouseup = null;
            };
        };
    }
}